<?php
namespace app\api\controller\kuang;
use app\api\controller\Common;
use think\Db;
class Xuexi extends Common{	//学习中心 需验证登陆
	public function _empty($name){
        die('非法访问！你的IP已被监控！');
    }
    public function kaoti(){   //考题显示
        $appdata = $this->appdata;      //接收的所有数据 含header
        $userinfo = $this->userinfo;    //用户信息
        $setting = $this->setting;      //系统参数
        // apifasong($appdata);

        //获取题目列表
        $lists=db('xuexi_xuanzeti')->where('zt',1)->select();
        if($lists){
            $count=db('xuexi_xuanzeti')->where('zt',1)->count();
            apifasong(['zt'=>'1','lists'=>$lists,'count'=>$count,'kaofen'=>$userinfo['kaofen']]);
        }else{
            apifasong(['zt'=>'0','msg'=>'还没有资料']);
        }
    }
    public function kaoti_do(){   //分数提交
        $appdata = $this->appdata;      //接收的所有数据 含header
        $userinfo = $this->userinfo;    //用户信息
        $setting = $this->setting;      //系统参数
        // apifasong($appdata);

        if(!isset($appdata['fenshu'])){
            apifasong(['zt'=>'-1','msg'=>'非法操作']);
        }
        $ret = db('user')->where('id',$userinfo['id'])->update(['kaofen'=>$appdata['fenshu']]);
        if($ret){
            //判断升级 分数比上次提高了 && 分数达到下一等级了
            if($userinfo['lv']>0 && $userinfo['lv']<5){
                $lv_next = $userinfo['lv'] + 1;
                if($userinfo['kaofen']<$appdata['fenshu'] && $appdata['fenshu']>=$setting['d_kaofen_lv'.$lv_next]){
                    auto_uplv($userinfo['id']);
                }
            }
            apifasong(['zt'=>'1']);
        }else{
            apifasong(['zt'=>'0','msg'=>'还没有资料']);
        }
    }
}






